package io.renren.modules.work.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Map;

import cn.hutool.core.bean.BeanUtil;
import io.renren.common.utils.ConfigConstant;
import io.renren.vo.ScSignEntityDTO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.work.entity.ScSignEntity;
import io.renren.modules.work.service.ScSignService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 工时登记
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-05-26 18:24:19
 */
@RestController
@RequestMapping("work/scsign")
public class ScSignController {
    @Autowired
    private ScSignService scSignService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("work:scsign:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = scSignService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{signid}")
    @RequiresPermissions("work:scsign:info")
    public R info(@PathVariable("signid") String signid){
		ScSignEntity scSign = scSignService.getById(signid);

        return R.ok().put("scSign", scSign);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("work:scsign:save")
    public R save(@RequestBody ScSignEntity scSign) throws ParseException {
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//        ScSignEntity scSignEntity = new ScSignEntity();
//        BeanUtil.copyProperties(scSign,scSignEntity);
//        scSignEntity.setSigntime(simpleDateFormat.parse(scSign.getSigntime()));
//        scSignEntity.setLeavetime(simpleDateFormat.parse(scSign.getLeavetime()));
        scSign.setSignno(ConfigConstant.generateSignNo());
        scSignService.save(scSign);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("work:scsign:update")
    public R update(@RequestBody ScSignEntity scSign){
		scSignService.updateById(scSign);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("work:scsign:delete")
    public R delete(@RequestBody String[] signids){
		scSignService.removeByIds(Arrays.asList(signids));

        return R.ok();
    }

}
